<?php

namespace App\Http\Controllers\Api;

use App\EducationExperience;
use App\EduWorkLabel;
use App\Http\Services\FileManager;
use App\Http\Services\UserManager;
use App\JobType;
use App\Resume;
use App\SetTopRecord;
use App\SkillLabel;
use App\User;
use App\Userinfo;
use App\WorkExperience;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class ResumeController extends Controller
{

    public function addResume(Request $request){

        $type                       =$request->get('type');
        $type_id                       =!is_null($request->get('type_id'))?$request->get('type_id'):0;
        //todo 基本资料
        $realname                   = $request->get('realname');
        $sex                        = $request->get('sex');
        $age                        = $request->get('age');
        $phone                      = $request->get('phone');
        $photo_id                   = $request->get('photo_id');
        $education                  = $request->get('education');
        $skill                      = $request->get('skill');
        $work_experience_num        = $request->get('work_experience_num');
        $email                      = $request->get('email');
        $desc                       = $request->get('desc');
        $wx                         = $request->get('wx');


        //todo 求职期望
        $job_status                 = $request->get('job_status');
        $province                   = $request->get('province');
        $city                       = $request->get('city');
        $area                       = $request->get('area');
        $town                       =$request->get('town');
        $work_nature                = $request->get('work_nature');
        $job_type_id                = $request->get('job_type_id');
        $expected_salary_type       = $request->get('expected_salary_type');
        $expected_salary            = $request->get('expected_salary');



        //todo 教育经历
        $school_name                =$request->get('school_name');
        $professional_name          =$request->get('professional_name');
        $education_name             =$request->get('education_name');
        $education_start_time       =$request->get('education_start_time');
        $education_end_time         =$request->get('education_end_time');
        $education_desc             =$request->get('education_desc');


        //todo 工作经验

        $work_name                  =$request->get('work_name');
        $work_job_title             =$request->get('work_job_title');
        $work_start_time            =$request->get('work_start_time');
        $work_end_time              =$request->get('work_end_time');
        $work_desc                  =$request->get('work_desc');


        //todo 技能标签
        $label_id                   =$request->get('label_id');


        /** @var Userinfo $user */
        $user=UserManager::isLogin($request);
        if(!$user)
            return response()->json(['level' => 'error','message' => '请先登录！',"data"=>"no_login"]);

        $userInfo = Userinfo::whereUserId($user->id)->first();
        if(!$userInfo)
            return response()->json(['level' => 'error','message' => '用户数据错误！']);


        if($type=="baisc_data"){

            if(is_null($sex)|| $sex=="")
                return response()->json(['level' => 'error','message' => '请选择性别！']);

            if(is_null($photo_id)||$photo_id=="")
                return response()->json(['level' => 'error','message' => '请上传头像！']);

            if(is_null($realname)||$realname==""||preg_match('/\d/is',$realname)||strlen($realname)>12)
                return response()->json(['level' => 'error','message' => '姓名个数不正确！']);


            $userInfo = Userinfo::whereUserId($user->id)->first();
            if(!$userInfo)
                return response()->json(['level' => 'error','message' => '用户数据错误！']);

            $userInfo->sex=$sex;
            $userInfo->photo_id=$photo_id;
            $userInfo->skill=$skill;
            $userInfo->realname=$realname;
            $userInfo->save();


            if(!preg_match("/^1[345789]{1}\d{9}$/",$phone))

                return response()->json(['level' => 'error','message' => '手机号码格式不正确！']);

            $newResume=Resume::whereUserId($user->id)->first();
            if (!$newResume)
                $newResume = new  Resume();


            $newResume->user_id = $user->id;
            if(!is_null($age))$newResume->age = $age;
            if(!is_null($email))$newResume->email=$email;
            if(!is_null($wx))$newResume->wx=$wx;
            $newResume->phone = $phone;
            if(!is_null($education))$newResume->education = $education;
            if(!is_null($work_experience_num))$newResume->work_experience_num=$work_experience_num;
            $newResume->save();


            $result['baisc_data'] = array(
                "user_info" => $userInfo,
                "resume"    => $newResume
            );
        }


        if($userInfo->realname=="")
            return response()->json(['level' => 'error','message' => '请填写基本信息！']);


        if($type=="job_intention"){


            $newResume=Resume::whereUserId($user->id)->first();
            if (!$newResume)
                $newResume = new  Resume();

            if (!is_null($job_status))$newResume->job_status=$job_status;
            if(!is_null($province))$newResume->province = $province;
            if(!is_null($city))$newResume->city = $city;
            if(!is_null($area))$newResume->area = $area;
            if(!is_null($work_nature))$newResume->work_nature = $work_nature;
            if(!is_null($expected_salary_type))$newResume->expected_salary_type=$expected_salary_type;
            if(!is_null($expected_salary))$newResume->expected_salary = $expected_salary;
            if(!is_null($job_type_id))$newResume->job_type_id = $job_type_id;
            if(!is_null($town))$newResume->town=$town;
            $newResume->state=1;

            $newResume->save();

            $result['job_intention']=$newResume;

        }



        if($type==1){
            $result="1";
            if($userInfo->realname=="")
                return response()->json(['level' => 'error','message' => '请填写基本信息！']);

            $resume=Resume::whereUserId($user->id)->first();
            if (!$resume)
                return response()->json(['level' => 'error','message' => '请填写基本信息！']);
           }






        //todo 描述
        if($type=="desc"){

            $newResume=Resume::whereUserId($user->id)->first();
            if(!$newResume)
            return response()->json(['level' => 'error','message' => '请写完成基本资料和求职期望的填写！']);

            if(!is_null($desc))$newResume->desc=$desc;
            $newResume->save();
            $result['desc']=$newResume->desc;
        }



        //todo 教育经历
        if($type=="education_experience"){

            $newResume=Resume::whereUserId($user->id)->first();
            if(!$newResume)
                return response()->json(['level' => 'error','message' => '请写完成基本资料和求职期望的填写！']);

            if(is_null($school_name)||$school_name=="")
                return response()->json(['level' => 'error','message' => '请填写学校名称！']);

            if(is_null($professional_name)||$professional_name=="")
                return response()->json(['level' => 'error','message' => '请输入专业名称！']);

            if(is_null($education_name)||$education_name=="")
                return response()->json(['level' => 'error','message' => '请选择最高学历！']);

            if(is_null($education_start_time)||$education_start_time=="")
                return response()->json(['level' => 'error','message' => '请选择开始时间！']);


            if(is_null($education_end_time)||$education_end_time=="")
                return response()->json(['level' => 'error','message' => '请选择结束时间！']);

            if(strtotime($work_start_time)>strtotime($work_end_time))
                return response()->json(['level' => 'error','message' => '开始时间不能大于结束时间']);

            if(strtotime($work_start_time)>time())
                return response()->json(['level' => 'error','message' => '开始时间填写不正确']);
            $edu=EduWorkLabel::whereType('edu')->whereUserId($user->id)->whereTypeId($type_id)->first();
            if(!$edu){

                $educationExperience=new EducationExperience();
                $educationExperience->user_id=$user->id;
                $educationExperience->name=$school_name;
                $educationExperience->professional_name=$professional_name;
                $educationExperience->education=$education_name;
                $educationExperience->start_time=$education_start_time;
                $educationExperience->end_time=$education_end_time;
                $educationExperience->desc=$education_desc;
                $educationExperience->save();



                $newEdu=new EduWorkLabel();
                $newEdu->user_id=$user->id;
                $newEdu->type="edu";
                $newEdu->type_id=$educationExperience->id;
                $newEdu->save();

            }else{

                $educationExperience=EducationExperience::whereId($edu->type_id)->first();

                if(!$educationExperience)
                    return response()->json(['level' => 'error','message' => '没找到简历信息！']);
                $educationExperience->user_id=$user->id;
                $educationExperience->name=$education_name;
                $educationExperience->professional_name=$professional_name;
                $educationExperience->education=$education_name;
                $educationExperience->start_time=$education_start_time;
                $educationExperience->end_time=$education_end_time;
                $educationExperience->desc=$education_desc;
                $educationExperience->save();

            }
            $result['education_experience']=$educationExperience;


        }

        //todo 工作经历
        if($type=="work_experience"){

            $newResume=Resume::whereUserId($user->id)->first();
            if(!$newResume)
                return response()->json(['level' => 'error','message' => '请写完成基本资料和求职期望的填写！']);

            if(is_null($work_name)||$work_name=="")
                return response()->json(['level' => 'error','message' => '请输入公司名称！']);

            if(is_null($work_job_title)||$work_job_title=="")
                return response()->json(['level' => 'error','message' => '请输入职位名称！']);

            if(is_null($work_start_time)||$work_start_time=="")
                return response()->json(['level' => 'error','message' => '请选择开始时间！']);

            if(is_null($work_end_time)||$work_end_time=="")
                return response()->json(['level' => 'error','message' => '请选择结束时间！']);

            if(strtotime($work_start_time)>strtotime($work_end_time))
                return response()->json(['level' => 'error','message' => '开始时间不能大于结束时间']);

            if(strtotime($work_start_time)>time())
                return response()->json(['level' => 'error','message' => '开始时间填写不正确']);


            $work=EduWorkLabel::whereType('work')->whereUserId($user->id)->whereTypeId($type_id)->first();

            if(!$work){

                $workExperience=new WorkExperience();
                $workExperience->user_id=$user->id;
                $workExperience->name=$work_name;
                $workExperience->job_title=$work_job_title;
                $workExperience->start_time=$work_start_time;
                $workExperience->end_time=$work_end_time;
                $workExperience->desc=$work_desc;
                $workExperience->save();


                $newWork=new EduWorkLabel();
                $newWork->user_id=$user->id;
                $newWork->type="work";
                $newWork->type_id=$workExperience->id;
                $newWork->save();
            }

            else{
                $workExperience=WorkExperience::whereId($work->type_id)->first();
                if(!$workExperience)
                    return response()->json(['level' => 'error','message' => '没找到简历信息！']);

                $workExperience->user_id=$user->id;
                $workExperience->name=$work_name;
                $workExperience->job_title=$work_job_title;
                $workExperience->start_time=$work_start_time;
                $workExperience->end_time=$work_end_time;
                $workExperience->desc=$work_desc;
                $workExperience->save();

                }
            $result['work_experience']=$workExperience;


        }
            if($type=="skill_label"){

                $newResume=Resume::whereUserId($user->id)->first();
                if(!$newResume)
                    return response()->json(['level' => 'error','message' => '请写完成基本资料和求职期望的填写！']);

            if(is_array($type_id)){
                $label=EduWorkLabel::whereUserId($user->id)->whereType("label")->first();
                $type_id=implode(",",$type_id);
                if(!$label)
                    $label=new EduWorkLabel();
                $label->label_id=$type_id;
                $label->user_id=$user->id;
                $label->type="label";
                $label->save();
            }
            $result['skill_label']=$label;
        }






        return response()->json(['level' => 'success','message' => '设置成功','data' => $result]);
    }



    public function  getUserResume(Request $request){

        $user =UserManager::isLogin($request);
        if(!$user)
            return response()->json(['level' => 'error','message' => '请先登录！',"data"=>"no_login"]);

        /** @var Resume $thatResume */
        $thatResume = Resume::whereUserId($user->id)->first();

        if (!$thatResume)
            return response()->json(['level' => 'error','message' => '未填写个人简历！']);

        $thatUserInfo = Userinfo::whereUserId($user->id)->first();
        if(!$thatUserInfo)
            return response()->json(['level' => 'error','message' => '用户数据错误！']);

        $thatUserInfo->photo_url = FileManager::getImgFromOssUrl($thatUserInfo->photo_id);

//        $thatJobType=JobType::whereId($thatResume->job_type_id)->first();
//
//        $jobName = $thatJobType ? $thatJobType->name : "无";

        $thatResume->user_info = $thatUserInfo;

        if($thatResume->position_type == 'short'){
            $thatResume->position_type = '短期工';
        }elseif($thatResume->position_type == 'long'){
            $thatResume->position_type = '长期工';
        }else{
            $thatResume->position_type = '未知';
        }
//        $thatResume->job_name = $jobName;

//        $name=['edu','work','label'];
//
//
//        $eduWorkLabel=EduWorkLabel::whereUserId($user->id)->get();
//        /*
//                $thatResume['edu']=array();
//                $thatResume['work']=array();
//                $thatResume['label']=array();*/
//        $result=array();
//
//        if(count($eduWorkLabel)>0){
//            if(count($name)>0){
//                foreach ($name as $value){
//                    $type['name']=$value;
//                    $type['list']=array();
//
//                    $thatResume[$value]=array();
//
//
//
//                    $items=EduWorkLabel::whereType($value)->whereUserId($user->id)->get();
//                    $typeIds=array();
//                    if(count($items)>0){
//                        foreach($items as $item){
//                            if ($value=="label"){
//                                $typeIds = explode( ',',$item->label_id);
//
//                            }
//                            else{
//                                array_push($typeIds,$item->type_id);
//                            }
//                        }
//                    }
//
//                    if(count($typeIds)>0){
//                        foreach ($typeIds as $typeId) {
//
//                            if ($value == "edu") {
//                                $resume = EducationExperience::whereId($typeId)->first();
//                            }
//                            if ($value == "work") {
//                                $resume = WorkExperience::whereId($typeId)->first();
//                            }
//                            if ($value == "label") {
//                                $resume = SkillLabel::whereId($typeId)->first();
//                            }
//
//                            if($resume){
//                                array_push($type['list'], $resume);
//
//                            }
//
//                        }
//                    }
//                    /*                array_push($thatResume,$type);*/
//                    $thatResume[$value]=$type['list'];
//                    /*                array_push($result,$type);*/
//
//                }
//
//            }
//        }else{
//            $thatResume['edu']=[];
//            $thatResume['work']=[];
//            $thatResume['label']=[];
//        }
        /*        $thatResume->edu_word_label=$result;*/

        return response()->json(['level' => 'success','message' => '获取成功','data' =>$thatResume]);
    }


    public  function getLabel(Request $request){

        $user =UserManager::isLogin($request);
        if(!$user)
            return response()->json(['level' => 'error','message' => '请先登录！',"data"=>"no_login"]);

        $label=SkillLabel::orderBy('created_at','desc')->get();

        return response()->json(['level' => 'success','message' => '获取成功','data' =>$label]);

    }


    public  function  delExperience(Request $request){


        $user =UserManager::isLogin($request);
        if(!$user)
            return response()->json(['level' => 'error','message' => '请先登录！',"data"=>"no_login"]);

        $type=$request->get('type');
        $type_id=$request->get('type_id');


        $eduWork=EduWorkLabel::whereType($type)->whereTypeId($type_id)->first();
        if(!$eduWork)
            return response()->json(['level' => 'error','message' => '该经历id不存在']);

        if($user->id !=$eduWork->user_id)
            return response()->json(['level' => 'error','message' => '不是你的简历信息，不能删除']);

        if($type=="edu"){

            $edu=EducationExperience::whereId($type_id)->first();
            if(!$edu)
                return response()->json(['level' => 'error','message' => '该经历id不存在']);
            $edu->delete();
            $data['edu']=$edu;
        }

        if($type=="work"){
            $work=WorkExperience::whereId($type_id)->first();
            if(!$work)
                return response()->json(['level' => 'error','message' => '该经历id不存在']);

            $work->delete();
            $data['work']=$work;
        }

        $eduWork->delete();
        return response()->json(['level' => 'success','message' => '删除成功','data'=>$data]);

    }


    public  function  getAllResume(Request $request){


        $user =UserManager::isLogin($request);
        if(!$user)
            return response()->json(['level' => 'error','message' => '请先登录！',"data"=>"no_login"]);

        $limit      = !is_null($request->get('limit')) ? $request->get('limit') : 20;
        $page       = !is_null($request->get('page')) ? $request->get('page') : 0;
//        $industryId  = !is_null($request->get('industry_id')) ? $request->get('industry_id'):0;
//        $jobId       = !is_null($request->get('job_id')) ? $request->get('job_id'):0;
        $province        = $request->get('province');
        $city            = $request->get('city');
        $area            = $request->get('area');
        $addressDetail   = $request->get('address_detail');
//        $town        = $request->get('town');
//        $salaryType  = $request->get('salary_type');
//        $salaryRange = $request->get('salary_range');
//        $type        = $request->get('type') ? $request->get('type') : "all_list";
//        $edu         = $request->get('education');
        $positionType    = $request->get('position_type');
//        $status      = $request->get('status');
//        $is_top      = $request->get('is_top');
//        $keyword     = $request->get('keyword');

//        if(!is_null($keyword) || $keyword != ''){
//            $joys = JobType::where('name','like','%'.$keyword.'%')->get();
//
//            $joyIds = [];
//            if(count($joys) > 0 ){
//                foreach ($joys as $joy){
//                    array_push($joyIds,$joy->id);
//                }
//            }
//            $resumes = DB::table('resume')->whereNull("deleted_at")->where('desc','like','%'.$keyword.'%')->whereState(1)->orWhere(function ($query) use($joyIds){
//                $query->whereIn('job_type_id',$joyIds)->whereNull("deleted_at");
//            })->get();
//        }else{

            $resumes = DB::table("resume")->whereNull("deleted_at");



//            if($jobId !='' && $jobId !=0){
//                $resumes = $resumes->whereJobTypeId($jobId);
//            }

            if(!is_null($positionType) && $positionType != ''){
                $resumes = $resumes->wherePositionType($positionType);
            }

            if(!is_null($province) && $province != ""){
                $resumes = $resumes->whereProvince($province);
            }

            if(!is_null($city) && $city !=""){
                $resumes = $resumes->whereCity($city);
            }

            if(!is_null($area) && $area != ""){
                $resumes = $resumes->whereArea($area);
            }

            if(!is_null($addressDetail) && $addressDetail != ''){
                $resumes = $resumes->whereAddressDetail($addressDetail);
            }

//            if(!is_null($town) && $town != ""){
//                $resumes = $resumes->whereTown($town);
//            }
//            if(!is_null($salaryType) && $salaryType != ""){
//                $resumes = $resumes->whereExpectedSalaryType($salaryType);
//            }

//            if(!is_null($salaryRange) && $salaryRange != ""){
//                $arr = explode("-",$salaryRange);
//                $resumes = $resumes->whereBetween('expected_salary',[$arr[0],$arr[1]]);
//            }
//            if(!is_null($edu) && $edu!==""){
//                $resumes=$resumes->whereEducation($edu);
//            }

//            if(!is_null($is_top) && $is_top == 1){
//                $resumes = $resumes->orWhere("set_top","=",1)->whereNull("deleted_at");
//            }
//            $resumes = $resumes->whereState(1)->orderBy("set_top","desc")->orderBy('sort','asc')->orderBy("reload_time","desc")->offset($limit * $page)->limit($limit)->get();
//        }

        $resumes = $resumes->whereState(1)->orderBy("created_at","desc")->offset($limit * $page)->limit($limit)->get();
        if(count($resumes)>0){
            foreach ($resumes as $resume){

//                if($resume->set_top == 1){
//                    //置顶判断
//                    $setTopRecord = SetTopRecord::whereResumeId($resume->id)->whereStatus(1)->where("end_time",">",date("Y-m-d H:i:s",time()))->first();
//                    if(!$setTopRecord){
//                        DB::table('resume')->where("id",$resume->id)->update(["set_top"=>0]);
//                    }
//                }


//                $thatJobType=JobType::whereId($resume->job_type_id)->first();
//
//                $resume->jobName = $thatJobType ? $thatJobType->name : "无";

                /** @var Userinfo $userInfo */
                $userInfo=Userinfo::whereUserId($resume->user_id)->first();
                if($userInfo){
                    $userInfo->photo_url = FileManager::getImgFromOssUrl($userInfo->photo_id);
                    $resume->user_info = $userInfo;
                }else{
                    $resume->user_info = null;
                }

                if($resume->position_type == 'short'){
                    $resume->position_type = '短期工';
                }elseif($resume->position_type == 'long'){
                    $resume->position_type = '长期工';
                }else{
                    $resume->position_type = '未知';
                }

//                $labelIds=EduWorkLabel::whereUserId($resume->user_id)->whereType('label')->first();
//                if(!$labelIds){
//
//                    $resume->skill_label=[];
//                }else{
//                    $typeIds = explode( ',',$labelIds->label_id);
//
//                    $tag=array();
//                    if(count($typeIds)>0){
//                        foreach ($typeIds as $typeId) {
//
//                            $label_name = SkillLabel::whereId($typeId)->first();
//
//
//                            if($label_name){
//                                array_push( $tag,$label_name->name);
//
//                            }
//                        }
//                    }
//                    $resume->skill_label=$tag;
//                }

            }

        }

        return response()->json(['level' => 'success','message' => '获取成功','data' =>$resumes]);
    }

    public  function  resumeDetail(Request $request){

        $resume_id=$request->get('resume_id');
        $user =UserManager::isLogin($request);
        if(!$user)
            return response()->json(['level' => 'error','message' => '请先登录！',"data"=>"no_login"]);

        /** @var Resume $thatResume */
        $thatResume=Resume::whereId($resume_id)->first();
        if(!$thatResume)
            return response()->json(['level' => 'error','message' => '简历已经被删除！']);



        $userInfo=Userinfo::whereUserId($user->id)->first();
        $companyAuth=$userInfo?$userInfo->company_auth:null;
        $personalAuth=$userInfo?$userInfo->personal_auth:null;

        if(( $personalAuth || $companyAuth || $thatResume->user_id==$user->id)==0)
            return response()->json(['level' => 'error','message' => '查看求职者的简历需要完成认证！']);


        $thatUserInfo = Userinfo::whereUserId($thatResume->user_id)->first();
        if(!$thatUserInfo)
            return response()->json(['level' => 'error','message' => '用户数据错误！']);


        $thatUserInfo->photo_url = FileManager::getImgFromOssUrl($thatUserInfo->photo_id);

//        $thatJobType=JobType::whereId($thatResume->job_type_id)->first();
//
//        $jobName = $thatJobType ? $thatJobType->name : "无";

        $thatResume->user_info = $thatUserInfo;
//        $thatResume->job_name = $jobName;

//        $name=['edu','work','label'];
//
//
//        $eduWorkLabel=EduWorkLabel::whereUserId($thatResume->user_id)->get();
//        /*
//                $thatResume['edu']=array();
//                $thatResume['work']=array();
//                $thatResume['label']=array();*/
//        $result=array();
//
//        if(count($eduWorkLabel)>0){
//            if(count($name)>0){
//                foreach ($name as $value){
//                    $type['name']=$value;
//                    $type['list']=array();
//
//                    $thatResume[$value]=array();
//
//
//
//                    $items=EduWorkLabel::whereType($value)->whereUserId($thatResume->user_id)->get();
//                    $typeIds=array();
//                    if(count($items)>0){
//                        foreach($items as $item){
//                            if ($value=="label"){
//                                $typeIds = explode( ',',$item->label_id);
//
//                            }
//                            else{
//                                array_push($typeIds,$item->type_id);
//                            }
//                        }
//
//
//                        if(count($typeIds)>0){
//                            foreach ($typeIds as $typeId) {
//
//                                if ($value == "edu") {
//                                    $resume = EducationExperience::whereId($typeId)->first();
//                                }
//                                if ($value == "work") {
//                                    $resume = WorkExperience::whereId($typeId)->first();
//                                }
//                                if ($value == "label") {
//                                    $resume = SkillLabel::whereId($typeId)->first();
//                                }
//                                if ($resume){
//                                    array_push($type['list'], $resume);
//                                }
//
//                            }
//                        }
//                        $thatResume[$value]=$type['list'];
//                    }
//                }
//            }
//        }else{
//            $thatResume['edu']=[];
//            $thatResume['work']=[];
//            $thatResume['label']=[];
//        }

        return response()->json(['level' => 'success','message' => '获取成功','data' =>$thatResume]);

    }

    public function buildResume(Request $request){
        /** @var User $user */
        $user = UserManager::isLogin($request);
        if(!$user)
            return response()->json(['level' => 'error','message' => '请先登录!','data' => 'no_login']);

        $desc                       = $request->get('desc');
        $positionType               = $request->get('position_type');
        $province                   = $request->get('province');
        $city                       = $request->get('city');
        $area                       = $request->get('area');
        $addressDetail              = $request->get('address_detail');
        $phone                      = $request->get('phone');
        $id                         = !is_null($request->get('id')) ? $request->get('id') : 0;

        if(is_null($desc) || $desc == '')
            return response()->json(['level' => 'error','message' => '请输入信息']);

        if(is_null($positionType) || $positionType == '')
            return response()->json(['level' => 'error','message' => '请选择职位类型']);

        if(!preg_match("/^1[345789]{1}\d{9}$/",$phone))
            return response()->json(['level' => 'error','message' => '手机号码格式不正确！']);

        $newResume = Resume::whereId($id)->first();
        if(!$newResume)
            $newResume = new Resume();

        $newResume->user_id                                           = $user->id;
        $newResume->desc                                              = $desc;
        $newResume->position_type                                     = $positionType;
        if(!is_null($province))$newResume->province                   = $province;
        if(!is_null($city))$newResume->city                           = $city;
        if(!is_null($area))$newResume->area                           = $area;
        if(!is_null($addressDetail))$newResume->address_detail        = $addressDetail;
        $newResume->phone                                             = $phone;
        $newResume->save();

        return response()->json(['level' => 'success','message' => '设置成功','data' => $newResume]);
    }

    public function deleteResume(Request $request){
        /** @var User $user */
        $user = UserManager::isLogin($request);
        if(!$user)
            return response()->json(['level' => 'error','message' => '请先登录!','data' => 'no_login']);

        $resumeId = !is_null($request->get('resume_id')) ? $request->get('resume_id') : 0;

        $thatResume = Resume::whereId($resumeId)->whereUserId($user->id)->first();
        if(!$thatResume)
            return response()->json(['level' => 'error','message' => '简历不存在']);

        $thatResume->delete();

        return response()->json(['level' => 'success','message' => '删除成功','data' => $thatResume]);
    }
}
